package com.snail.snailvr.views.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.snail.snailvr.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Jason on 16/4/15
 */
public class ClientListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private LayoutInflater mInflater;
    private List<String> mClientLists;

    public ClientListAdapter(Context context, List<String> clientList) {
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mClientLists = clientList;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ContentHolder(mInflater.inflate(R.layout.client_list_item, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ContentHolder) {
            ContentHolder viewHolder = (ContentHolder) holder;
            String name = getItem(position);

            if (name != null) {
                viewHolder.content.setText(name);
            }
        }
    }

    @Override
    public int getItemCount() {
        return mClientLists.size();
    }

    public String getItem(int position) {
        if (position < getItemCount())
            return mClientLists.get(position);

        return null;
    }


    static class ContentHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.contentTextView)
        TextView content;

        public ContentHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
